#include "stdafx.h"
#include <iostream>
#include <pthread.h>
#include "DemoThreads.h"


void *threadFunc( void *p_arg ) {
	int number = reinterpret_cast<int>(p_arg);
	for (int i = 0; i < 5000; i++) {
		cout << "Dans *threadFunc " << endl;
		cout << " " <<  number << " "  << endl;
	}
	return nullptr;
}


void testThreads() {
	pthread_t t1, t2;
	void *result = nullptr;

	cout << endl;
	cout << "--------------------------------------------------" << endl;

	cout << "** Creating thread..." << endl;
	if (pthread_create( &t1, 0, threadFunc, (void *) 1 ) != 0) {
		cerr << "** FAIL 1" << endl;
		return;
	}
	else {
		cout << "** Thread 1 creation OK" << endl;
	}

	if (pthread_create( &t2, 0, threadFunc, (void *) 2 ) != 0) {
		cerr << "** FAIL 2" << endl;
		return;
	}
	else {
		cout << "** Thread 2 creation OK" << endl;
	}

	cout << "** Waiting..." <<endl;
	pthread_join( t1, &result );
	pthread_join( t2, &result );

	return;
}
